#!/usr/bin/perl
use strict;
use warnings;
use Test::More tests => 11;


BEGIN { use_ok('Test::WWW::Mechanize::Catalyst', 'WIAB');
        use FindBin;
        require "$FindBin::Bin/bin/make_test_env.pl";

    }

END { require FindBin;
       require "$FindBin::Bin/bin/remove_test_env.pl"
   }


my $mech = Test::WWW::Mechanize::Catalyst->new;


# need to log in to do writes.  This is tested in 04controller_User.t

$mech->get_ok('http://localhost/login');
$mech->submit_form(
    form_name => 'login',
    fields => {    user => 'test',
                   password => 'test'
               }
);

# create sub page of front page
$mech->follow_link_ok({text => 'New page'}, 'get add new page');
$mech->submit_form(
    form_name => 'edit',
    fields => {    page_title => 'one',
                   page_content => "h1. Page 1\n\nThis is page 1\n",
               }
);
$DB::single=1;
like($mech->uri, qr{content/one/?$}, 'redirected to new page');

$mech->content_contains('This is page 1', 'page created successfully');
# test move and edit existing page
$DB::single=1;
$mech->follow_link_ok({text => 'Edit this page'}, 'get edit this page');
$mech->submit_form(
    form_name => 'edit',
    fields => {    page_title => 'one a',
                   page_content => "h1. Page 1\n\nThis is page 1 edited\n",
               }
);
like($mech->uri, qr{content/one_a/?$}, 'redirected to edited page');
$mech->content_contains('This is page 1 edited', 'page edited successfully');
$mech->content_contains('Delete this page', 'can delete this page');
$mech->follow_link_ok({text => 'Delete this page'}, 'delete page');
$mech->content_lacks({text => 'one a'}, 'page deteted successfully');


# next up, make sure that nested dirs test ok and that the two menu
# bars look ok.

